package multithread;

//单例模式 饿汉模式

class Singleton {
    private static Singleton instance = new Singleton();//singleton 唯一的实例

    public static Singleton getInstance(){
        return instance;
    }

    private Singleton(){
        //构造函数设为私有，无法new Singleton对象
        //只能通过getInstance获得唯一的实例
    }
}

public class ThreadDemo8 {
    public static void main(String[] args) {
        //不能实例Singleton对象
        //Singleton s = new Singleton();

        //只能通过getInstance方法得到唯一的实例
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();


    }
}
